Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce PagedVector class #13808

Merged
merged 1 commit into from
Jan 18, 2024
Merged

Conversation

ktf
Copy link
Contributor

@ktf ktf commented Oct 5, 2023

The goal of the class is to be an (almost) drop in replacement for SmallVector and std::vector when those are presized and filled later, as it happens in SourceManager and ASTReader.

By splitting the actual vector in pages of the same size and allocating the pages only when they are needed, using this containers reduces the memory usage by a factor 4 for the cases relevant to the ALICE experiment ROOT / cling usage.

@ktf ktf requested a review from vgvassilev as a code owner October 5, 2023 11:50
@phsft-bot
Copy link
Collaborator

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac11/noimt, mac12arm/cxx20, windows10/default
How to customize builds

@github-actions
Copy link

github-actions bot commented Oct 5, 2023

Test Results

     9 files       9 suites   1d 20h 22m 36s ⏱️
 2 490 tests  2 490 ✅ 0 💤 0 ❌
21 378 runs  21 378 ✅ 0 💤 0 ❌

Results for commit b99836b.

♻️ This comment has been updated with latest results.

@vgvassilev
Copy link
Member

@ktf, this is a backport of llvm/llvm-project#66430 but does it include llvm/llvm-project#67958?

@hahnjo hahnjo self-requested a review October 6, 2023 07:57
@hahnjo
Copy link
Member

hahnjo commented Oct 6, 2023

@ktf this fails quite horribly in CI:

TFormulaGradientTests: /github/home/ROOT-CI/src/interpreter/llvm-project/clang/include/clang/Basic/SourceManager.h:1694: const clang::SrcMgr::SLocEntry& clang::SourceManager::getLocalSLocEntry(unsigned int) const: Assertion `Index < LocalSLocEntryTable.size() && "Invalid index"' failed.

@Axel-Naumann I'm not convinced this should be backported to 6.28, this has the potential to break a lot of things...

@Axel-Naumann
Copy link
Member

With the original PR accepted upstream and an experiment requesting this we need good reasons (such as "fails quite horribly in CI" :-) ) to refuse the backport. I think we want to work with @ktf to make this PR work...

@ktf the problem is that another patch release is imminent and this PR seems not yet ready for prime time. It will have to miss this train but take the next one.

@Axel-Naumann Axel-Naumann removed this from the 6.28/06 milestone Oct 6, 2023
@vgvassilev
Copy link
Member

Looks like we fail with TFormulaGradientTests: /github/home/ROOT-CI/src/interpreter/llvm-project/clang/include/clang/Basic/SourceManager.h:1694: const clang::SrcMgr::SLocEntry& clang::SourceManager::getLocalSLocEntry(unsigned int) const: Assertion `Index < LocalSLocEntryTable.size() && "Invalid index"' failed.

@vgvassilev
Copy link
Member

@hahnjo, the area in clang which @ktf touches hasn't been changing for years. Maybe we just discovered something that upstream has not and we need to tune the patch...

@hahnjo
Copy link
Member

hahnjo commented Oct 6, 2023

Looks like we fail with [...]

Yes, that's exactly what I posted 45 minutes ago...

@hahnjo, the area in clang which @ktf touches hasn't been changing for years. Maybe we just discovered something that upstream has not and we need to tune the patch...

Yes, that's what I'm saying. And IMHO that "tuning" should not happen after we broke everybody's ROOT in a minor patch release...

@vgvassilev
Copy link
Member

Looks like we fail with [...]

Yes, that's exactly what I posted 45 minutes ago...

@hahnjo, the area in clang which @ktf touches hasn't been changing for years. Maybe we just discovered something that upstream has not and we need to tune the patch...

Yes, that's what I'm saying. And IMHO that "tuning" should not happen after we broke everybody's ROOT in a minor patch release...

Agreed, let's fix the failures in the master and re-evaluate what should be done next.

@ktf
Copy link
Contributor Author

ktf commented Oct 6, 2023

I am checking what's going on. I might have simply screwed up the backport.

@ktf
Copy link
Contributor Author

ktf commented Oct 6, 2023

@ktf, this is a backport of llvm/llvm-project#66430 but does it include llvm/llvm-project#67958?

Not yet.

@ktf
Copy link
Contributor Author

ktf commented Oct 6, 2023

@ktf the problem is that another patch release is imminent and this PR seems not yet ready for prime time. It will have to miss this train but take the next one.

That's fine for me.

@ktf
Copy link
Contributor Author

ktf commented Oct 6, 2023

Needless to say that the (+ -DLLVM_ENABLE_ASSERTIONS=On) with my setup works fine. Investigating what difference I have in the build environment (I also already tried CXX20...).

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac11/noimt, mac12arm/cxx20, windows10/default
How to customize builds

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac11/noimt, mac12arm/cxx20, windows10/default
How to customize builds

@ktf
Copy link
Contributor Author

ktf commented Oct 6, 2023

The updated version should be closer to what is currently in llvm upstream...

@hahnjo
Copy link
Member

hahnjo commented Oct 6, 2023

The updated version should be closer to what is currently in llvm upstream...

What are the differences? Ideally we should apply the exact patch from upstream, it should cleanly go away on a future LLVM upgrade...

@ktf
Copy link
Contributor Author

ktf commented Oct 6, 2023

Apparently ROOT's llvm-project is not up-to-date.

@hahnjo
Copy link
Member

hahnjo commented Oct 10, 2023

Apparently ROOT's llvm-project is not up-to-date.

https://github.com/root-project/llvm-project/ matches what is currently in master. In this PR, you are modifying files in interpreter/llvm-project/, so of course these changes cannot be reflected in https://github.com/root-project/llvm-project/. This needs to be synchronized eventually, but first the test failures need to be addressed (across all platforms).

@vgvassilev
Copy link
Member

ping...

@vgvassilev
Copy link
Member

@ktf ping...

@phsft-bot
Copy link
Collaborator

Build failed on windows10/default.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

Errors:

  • [2024-01-08T10:30:44.430Z] CMake Error at C:/build/workspace/root-pullrequests-build/rootspi/jenkins/root-build.cmake:1126 (message):

@hahnjo
Copy link
Member

hahnjo commented Jan 8, 2024

I believe you have to rebase, not merge the master branch...

@phsft-bot
Copy link
Collaborator

Build failed on ROOT-performance-centos8-multicore/soversion.
Running on olbdw-01.cern.ch:/data/sftnight/workspace/root-pullrequests-build
See console output.

Errors:

  • [2024-01-08T11:22:19.257Z] CMake Error at /data/sftnight/workspace/root-pullrequests-build/rootspi/jenkins/root-build.cmake:1126 (message):

@phsft-bot
Copy link
Collaborator

Build failed on ROOT-ubuntu2004/python3.
Running on root-ubuntu-2004-3.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2024-01-08T11:25:22.212Z] stderr: error: Failed to merge in the changes.
  • [2024-01-08T11:25:26.936Z] CMake Error at /home/sftnight/build/workspace/root-pullrequests-build/rootspi/jenkins/root-build.cmake:1126 (message):

@phsft-bot
Copy link
Collaborator

Build failed on mac12arm/cxx20.
Running on 194.12.161.128:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2024-01-08T11:50:42.692Z] CMake Error at /Users/sftnight/build/workspace/root-pullrequests-build/rootspi/jenkins/root-build.cmake:1126 (message):

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac12arm/cxx20, windows10/default
How to customize builds

@phsft-bot
Copy link
Collaborator

Build failed on windows10/default.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

Failing tests:

@hahnjo
Copy link
Member

hahnjo commented Jan 8, 2024

@phsft-bot build with flags -DCTEST_TEST_EXCLUDE_NONE=ON

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac12arm/cxx20, windows10/default with flags -DCTEST_TEST_EXCLUDE_NONE=ON
How to customize builds

@phsft-bot
Copy link
Collaborator

Build failed on windows10/default.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

Failing tests:

@hahnjo hahnjo added the clean build Ask CI to do non-incremental build on PR label Jan 16, 2024
@hahnjo hahnjo self-assigned this Jan 16, 2024
The goal of the class is to be an (almost) drop in replacement for
SmallVector and std::vector when those are presized and filled later, as
it happens in SourceManager and ASTReader.

By doing so, sparsely accessed PagedVector can profit from reduced
memory footprint.

Co-authored-by: Jonas Hahnfeld <jonas.hahnfeld@cern.ch>
@phsft-bot
Copy link
Collaborator

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac12arm/cxx20, windows10/default
How to customize builds

@hahnjo
Copy link
Member

hahnjo commented Jan 16, 2024

Hi @ktf, as discussed yesterday the test failures are related to an issue in our incremental builds where Clad is not rebuilt after changes to the Clang headers. This leads to very weird symptoms because some "stale" functions access memory where they shouldn't and so on. I was hit by this problem already twice and it's tracked in #7977, so one would suppose that I remember by now but evidently I didn't... Apologies for the confusion and the delay it caused in integrating this.

I've now synchronized the changes to https://github.com/root-project/llvm-project/releases/tag/ROOT-llvm16-20240116-01, moving the header to clang/include/clang/Basic as mentioned yesterday to keep the ability to build against a vanilla version of LLVM). @vgvassilev I put the commit only into ROOT-llvm16, not cling-llvm16 because I think it's not that relevant for Cling standalone. Let me know if you disagree and I can of course move it.

Some measurements of this change on my machine: for a simple ./bin/root.exe -q, it reduces the maximum RSS from 217MB to 192MB and for ./bin/root.exe -q -e "std::vector<int> v" -e "return 0;" from 255MB to 230MB 👏

@ktf
Copy link
Contributor Author

ktf commented Jan 16, 2024

Very nice, thank you for your followup. Shall I close this one?

@ktf
Copy link
Contributor Author

ktf commented Jan 16, 2024

BTW, I think you can move IdentifiersLoaded to be a paged vector as well, although one would need to measure the effect on RSS.

@hahnjo
Copy link
Member

hahnjo commented Jan 16, 2024

Very nice, thank you for your followup. Shall I close this one?

No, please leave it open: I hijacked your branch and directly pushed the slightly modified commit there. It's currently running through our CI (which is a bit congested at the moment). Once all is green, we can merge 😃

BTW, I think you can move IdentifiersLoaded to be a paged vector as well, although one would need to measure the effect on RSS.

Ok, that's for a follow-up PR I would say.

@hahnjo hahnjo requested review from vgvassilev and removed request for vgvassilev January 17, 2024 07:24
Copy link
Member

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@hahnjo hahnjo merged commit 9c7bac0 into root-project:master Jan 18, 2024
16 checks passed
@hahnjo
Copy link
Member

hahnjo commented Jan 23, 2024

Hi @ktf, if we were to backport this to a release, which one would ALICE be interested in, 6.30? Or would you be fine keeping the patch locally in your stack for now?

@ktf
Copy link
Contributor Author

ktf commented Jan 23, 2024

Yes, we would need 6.30, but for now we are fine.

@ktf ktf deleted the reduce-memory-usage branch January 23, 2024 08:46
@hahnjo
Copy link
Member

hahnjo commented Jan 23, 2024

Yes, we would need 6.30, but for now we are fine.

Ok, I prepared #14411. To be seen if we already include it in 6.30.04 or only in .06

@ktf
Copy link
Contributor Author

ktf commented Jan 24, 2024

Perfect, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clean build Ask CI to do non-incremental build on PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants